package com.hui.controller;

import com.hui.model.People;
import com.hui.model.UserListForm;
import com.hui.model.UserMap;
import com.hui.model.UserSet;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * TODO: 集合数据绑定
 *
 * @author chenth
 * @create 2018-07-25 19:30
 **/
@Controller
public class CollectionController{
    /**
     * list集合的数据绑定
     * @param userListForm
     * @return
     * http://localhost:8080/userList.do?list[0].name=Lily&list[1].name=Tom
     */
    @RequestMapping("userList.do")
    @ResponseBody
    public String list(UserListForm userListForm){
        return userListForm.toString();
    }

    /**
     * set集合的数据绑定
     * set集合数据绑定要先初始化
     * @param userSet
     * @return
     * http://localhost:8080/userSet.do?set[0].name=Lily&set[1].name=Tom
     */
    @RequestMapping("userSet.do")
    @ResponseBody
    public String set(UserSet userSet){
        return userSet.toString();
    }

    /**
     * map集合的数据绑定
     * @param userMap
     * @return
     * http://localhost:8080/userMap.do?maps['X'].name=Tom&maps['X'].age=10&maps['Y'].name=Lucy
     */
    @RequestMapping("userMap.do")
    @ResponseBody
    public String map(UserMap userMap){
        return userMap.toString();
    }

}
